<?php
/**
 * For
 *
 * 'for' loops are the most complex loops in GOP. They behave like their
 * text-language counterparts.
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @since   gop1.0
 */
final class gop_For extends gop_BaseIterator {
    public function execute(gop_Base $_caller = null) {
        $this->setCaller($_caller);
        $G1 = $this->getContext()->getCallee($this->initialize)->execute($this);
        $G2 = $this->getContext()->getCallee($this->check);
        $G3 = $this->getContext()->getCallee($this->expression);
        for($G1; $G2->execute($this); $G3->execute($this)) {
            foreach($this->_outputs as $G) {
                $this->getContext()->getCallee($G)->execute($this);
                if ($this->_continue) {
                    $this->interuptContinue();
                    continue 2;
                }
                if ($this->_break) {
                    $this->interuptBreak();
                    break;
                }
                if ($this->_return) return;
            }
        }
        $this->chainExec();
    }
}
?>